package com.hzdl.car.sqlprovider;

import com.hzdl.car.util.Common;
import com.hzdl.car.vo.NewsVo;
import org.apache.ibatis.jdbc.SQL;

public class NewsSqlProvider {
    public String findNews(NewsVo newsVo){
        return new SQL(){{
            SELECT("*");
            FROM("sys_news");
            if(!Common.isEmpty(newsVo.getTitle())){
                WHERE("title like concat('%',#{title},'%')");
            }
            if(!Common.isEmpty(newsVo.getContent())){
                WHERE("content like concat('%',#{content},'%')");
            }
            if(newsVo.getCreateTime1()!=null){
                WHERE("createTime >= #{createTime1}");
            }
            if(newsVo.getCreateTime2()!=null){
                WHERE("createTime <= #{createTime2}");
            }
            ORDER_BY("createTime desc");
        }}.toString();
    }
}
